package sealte.mynode.servlet.impl;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sealte.mynode.bean.UserBean;
import sealte.mynode.pojo.User;
import sealte.mynode.servlet.system.SystemPostServlet;

public class UserLogin extends SystemPostServlet {

	private static final long serialVersionUID = 622289989306756826L;

	@Override
	protected void doBusinessService(HttpServletRequest req, HttpServletResponse resp) 
			throws ServletException, IOException {
		
		PrintWriter out = resp.getWriter();
		
		String name = req.getParameter("username");
		String pass = req.getParameter("userpass");
		UserBean ub = new UserBean();
		User user = ub.login(name, pass);
		if(null!=user){
			req.getSession().setAttribute("user", user);
			resp.sendRedirect("home.jsp");
		}else{
			out.println("Login failed!");
		}
		
		if(null!=out){
			out.close();
		}
	}
	
}
